#include <bits/stdc++.h>
using namespace std;
double d[100001], v[100001], a[100001], p[100001];
int g[100001];
bool flag[100001];
signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    while (t--)
    {
        memset(g, 0, sizeof(g));
        memset(flag, 0, sizeof(flag));
        int n, m, L, V;
        cin >> n >> m >> L >> V;
        for (int i = 1; i <= n; i++)
        {
            cin >> d[i] >> v[i] >> a[i];
        }
        for (int i = 1; i <= n; i++)
        {
            cin >> p[i];
        }
        int cnt = 0, ans = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] < 0)
            {
                int x = lower_bound(p + 1, p + n + 1, d[i]) - p;
                if (x <= 0)
                {
                    continue;
                }
                if (sqrt(v[i] * v[i] + 2 * a[i] * (p[x] - d[i])) > V)
                {
                    cnt++;
                    g[i] = upper_bound(p + 1, p + n + 1, (V * V - v[i] * v[i]) / (2 * a[i]) + d[i]) - p - 1;
                }
            }
            else if (a[i] == 0)
            {
                if (d[i] <= p[n] && v[i] > V)
                {
                    g[i] = n;
                    cnt++;
                }
            }
            else
            {
                if (sqrt(v[i] * v[i] + 2 * a[i] * (p[n] - d[i])) > V)
                {
                    cnt++;
                    ans = 1;
                }
            }
        }
        sort(g + 1, g + n + 1);
        for (int i = 1; i <= n; i++)
        {
            if (g[i] == 0)
            {
                continue;
            }
            ans += (!flag[g[i]]);
            int kkk = 1;
            while (g[i - kkk] >= d[i])
            {
                ans--;
                kkk++;
            }
            flag[g[i]] = true;
        }
        cout << cnt << ' ' << ans << endl;
    }
    return 0;
}
/*
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 ‐2
6 4 ‐4
2 5 8 9 15
*/
